/**
 * @fileOverview
 * @author iNahoo
 * @since 2019/11/14.
 */

const PCR = require('./pcr-operation/base');
const {sleep} = require('./pcr-operation/utils');

const runLimit = process.argv[2];

const instances = [
    new PCR(3, 7, 800, 400),
    new PCR(1, 450, 800, 400),
    new PCR(3, 905, 800, 400),
    new PCR(14, 1357, 800, 400),
];

async function run(task) {

    PCR.save();
    await sleep(50);

    const ins = runLimit ? instances.filter((v, i) => {
        const str = String(i + 1);
        return runLimit.match(str);
    }) : instances;

    await Promise.all(ins.map(async (I) => {
        await I.run(task);
    }));

    await sleep(50);
    PCR.restore();

    process.exit(0);
}

module.exports = {
    instances,
    run
};






